//司机载客时长
var workTimeChart = echarts.init(document.getElementById('workTime'));
workTimeChart.setOption({
    title: {
        text: '司机每日载客时间情况',
        left: 'left',
        top: '8%',
        textStyle: {
            color: '#fff',
            textShadowBlur: 3,
            textShadowOffsetY: 3,
        }
    },
    tooltip: {
        top: "6%",
        trigger: 'axis'
    },
    legend: {
        top: "12%",
        left: 'right',
        icon: 'circle',
        textStyle: {
            color: '#fff',
            fontFamily: '微软雅黑'
        },
        data: ['工作日', '周末', '假期']
    },
    grid: {
        left: '17%',
        top: '28%',
        height: '55%'
    },
    /*toolbox: {
        top: "12%",
        show: true,
        feature: {
            dataZoom: {
                yAxisIndex: 'none'
            },
            dataView: {readOnly: false},
            magicType: {type: ['line', 'bar']},
            restore: {},
            saveAsImage: {}
        }
    },*/
    xAxis: {
        data: [],
        type: 'category',
        boundaryGap: false,
        axisLabel: {
            textStyle: {
                color: '#fff'
            }
        },
        axisTick: {
            lineStyle: {
                color: '#0099FF'
            }
        }
    },
    yAxis: {
        type: 'value',
        axisLabel: {
            formatter: '{value} '
        },
        axisLabel: {
            textStyle: {
                color: '#fff'
            }
        }
    },
    series: [
        {
            name: '工作日',
            type: 'line',
            smooth: true,
            data: [],
            itemStyle: {
                normal: {
                    color: '#fba025',
                }
            }
        },
        {
            name: '周末',
            type: 'line',
            smooth: true,
            data: [],
            itemStyle: {
                normal: {
                    color: '#02defd',
                }
            }
        },
        {
            name: '假期',
            type: 'line',
            smooth: true,
            data: [],
            itemStyle: {
                normal: {
                    color: '#e71e18',
                }
            }
        }]
});
workTimeChart.showLoading();
var workTimeTypes = [];
var workTimeInWorkday = [];
var workTimeInWeekend = [];
var workTimeInHoliday = [];
$.ajax({
    type: "POST",
    async: true,
    url: "WorkTimeServlet",
    data: {},
    dataType: "json",
    success: function (resultOfWorkTime) {
        if (resultOfWorkTime) {
            for (var i = 0; i < 11; i++) {
                workTimeTypes.push(resultOfWorkTime[i].type);
                workTimeInWorkday.push(resultOfWorkTime[i].typeCount);
                workTimeInWeekend.push(resultOfWorkTime[i + 11].typeCount);
                workTimeInHoliday.push(resultOfWorkTime[i + 22].typeCount);

            }
            workTimeChart.hideLoading();
            workTimeChart.setOption({
                xAxis: {
                    data: workTimeTypes
                },
                series: [
                    {
                        data: workTimeInWorkday
                    },
                    {
                        data: workTimeInWeekend
                    },
                    {
                        data: workTimeInHoliday
                    }]
            })
        }
    },
    error: function (errorMsg) {
        alert("ERROR!!!!");
        workTimeChart.hideLoading();
    }
})